package cn.tedu.hotel.controller;

import cn.tedu.hotel.pojo.dto.CategoryAddNewDTO;
import cn.tedu.hotel.pojo.vo.CategoryListItemVO;
import cn.tedu.hotel.service.ICategoryService;
import cn.tedu.hotel.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  处理房间类型数据相关请求的控制器
 */
@Api(tags = "03. 房间类型管理模块")
@Slf4j
@RestController
@RequestMapping("/types")
public class CategoryController {


    @Autowired
    ICategoryService categoryService;

    public CategoryController(){
        log.debug("创建控制器：TypeController");
    }

    @ApiOperation("添加房间类型")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(CategoryAddNewDTO categoryAddNewDTO){
        log.debug("开始处理【添加房间类型】请求，参数：{}", categoryAddNewDTO);
        categoryService.addNew(categoryAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除房间类型")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.debug("开始处理【删除房间类型】的请求，id={}",id);
        categoryService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询房间类型列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("")
    public JsonResult<List<CategoryListItemVO>> listType(){
        log.debug("开始处理【查询房间类型列表】");
        List<CategoryListItemVO> typeListItemVOS = categoryService.listType();
        return JsonResult.ok(typeListItemVOS);
    }

    @ApiOperation("启用房间类型")
    @ApiOperationSupport(order = 401)
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long id) {
        log.debug("准备处理【启用房间类型】的请求：id={}", id);
        categoryService.setEnable(id);
        return JsonResult.ok();
    }

    @ApiOperation("禁用房间类型")
    @ApiOperationSupport(order = 402)
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long id) {
        log.debug("准备处理【禁用房间类型】的请求：id={}", id);
        categoryService.setDisable(id);
        return JsonResult.ok();
    }


    @ApiOperation("设置房间类型显示在导航栏")
    @ApiOperationSupport(order = 501)
    @PostMapping("/{id:[0-9]+}/is-display")
    public JsonResult<Void> setIsDisplay(@PathVariable Long id){
        log.debug("准备处理【设置房间类型显示在导航栏】的请求，id={}",id);
        categoryService.setIsDisplay(id);
        return JsonResult.ok();
    }

    @ApiOperation("设置房间类型不显示在导航栏")
    @ApiOperationSupport(order = 502)
    @PostMapping("/{id:[0-9]+}/not-display")
    public JsonResult<Void> setNotDisplay(@PathVariable Long id){
        log.debug("准备处理【设置房间类型显示在导航栏】的请求，id={}",id);
        categoryService.setNotDisplay(id);
        return JsonResult.ok();
    }


}
